package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.model.request.pc.ProductReqRequestBean;
import com.homedo.odin.solution.service.ProductReqServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhanglei
 * @date: 2018/4/25
 * @Description: PC 活动接口 API
 */
@Api(description = "需求", tags = {"Requirement"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/reqs")
public class RequirementController {

    @Autowired
    private ProductReqServiceImpl productReqService;

    @ApiOperation(value = "PC_产品资料提交需求", httpMethod = "POST")
    @PostMapping(value = "/products")
    public ResultData submitProductRequire(@Valid @RequestBody ProductReqRequestBean reqRequestBean,
            BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultData
                    .newInstance(new Meta(Meta.CODE_451.getCode(), bindingResult.getFieldError().getDefaultMessage()));
        }
        productReqService.submitProductRequire(reqRequestBean);
        return ResultData.newInstance();
    }


}
